//调用第三方接口, 获取天气信息

const http = require('http')

exports.queryWeather = (cityCode, callback)=>{

    options = {
        hostname: 'www.weather.com.cn',
        port: 80,
        protocol: "http:",
        path: '/data/sk/' + cityCode + '.html',
        header: {
            'Content-Type': 'application/x-www/form-urlencoded'
        },
        method: 'get'   //默认get
    }

    let req = http.request(options, (res)=>{
        let info = ''
        res.on('data', (chunk)=>{
            info += chunk
        })
        res.on('end', ()=>{
            info = JSON.parse(info)
            callback(info)
        })
    })

    req.end()
}